/**
 * fileName: IndexAction.java
 *     Date: 2012-4-27
 **/
package com.stranger.index.web.action;




import java.io.PrintWriter;
import java.util.List;



import com.opensymphony.xwork2.util.logging.LoggerUtils;
import com.stranger.common.core.BaseAction;
import com.stranger.common.core.PagerCallBack;
import com.stranger.common.util.MessageUtil;

import com.stranger.index.bean.TeachersBean;
import com.stranger.index.service.IIndexService;
import com.stranger.index.web.vo.UserVO;

/**
 * @作者 stranger.lin
 *
 * @时间 2012-4-27
 */
public class IndexAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private IIndexService indexService;
	
	private UserVO user,userVO;
	
	private List<UserVO> list;
	
	
	
	public String login(){
		try {
			TeachersBean bean =indexService.checkLogin(user);
			if (bean!=null) {
				getRequest().getSession().setAttribute("currentUser", bean);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return "loginSuccess";
	}
	
	public String initQueryTeacher(){
		
		return "initList";
	}
	
	public String queryTeacher() {
		try {
			
 			queryWithPager(new PagerCallBack() {
				
				public List<UserVO> callList() {
					
					try {
						list=indexService.findTeachersByWhere(userVO);
					} catch (Exception e) {
						e.printStackTrace();
					}
					return list;
				}
			});
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "json";
	}

	/**
	 * 初始化修改页面
	 * 
	 * */
	public String initInsert(){
		
		return "initInsert";
	}
	
	/**
	 * 添加教师
	 * 
	 * */
	public String insert(){
		PrintWriter out=null ;
		try {
			
			indexService.insert(user);
			
			
		} catch (Exception e) {
		
			LoggerUtils.format("添加教师出错");
			e.printStackTrace();
			
			setMsg(MessageUtil.msg("index00002"));
			return "json";
		}
		setMsg(MessageUtil.msg("index00001"));
		return "json";
	}
	
	
	public IIndexService getIndexService() {
		return indexService;
	}

	public void setIndexService(IIndexService indexService) {
		this.indexService = indexService;
	}

	public UserVO getUser() {
		return user;
	}

	public void setUser(UserVO user) {
		this.user = user;
	}

	public List<UserVO> getList() {
		return list;
	}

	public void setList(List<UserVO> list) {
		this.list = list;
	}

	public String getAddress() {
		return userVO.getAddress();
	}

	public String getEmail() {
		return userVO.getEmail();
	}

	public String getId() {
		return userVO.getId();
	}

	public String getNativeName() {
		return userVO.getNativeName();
	}

	public String getPassword() {
		return userVO.getPassword();
	}

	public String getRealName() {
		return userVO.getRealName();
	}

	public String getRole() {
		return userVO.getRole();
	}

	public String getSex() {
		return userVO.getSex();
	}

	public String getTel() {
		return userVO.getTel();
	}

	public String getUserName() {
		return userVO.getUserName();
	}

	public void setAddress(String address) {
		userVO.setAddress(address);
	}

	public void setEmail(String email) {
		userVO.setEmail(email);
	}

	public void setId(String id) {
		userVO.setId(id);
	}

	public void setNativeName(String nativeName) {
		userVO.setNativeName(nativeName);
	}

	public void setPassword(String password) {
		userVO.setPassword(password);
	}

	public void setRealName(String realName) {
		userVO.setRealName(realName);
	}

	public void setRole(String role) {
		userVO.setRole(role);
	}

	public void setSex(String sex) {
		userVO.setSex(sex);
	}

	public void setTel(String tel) {
		userVO.setTel(tel);
	}

	public void setUserName(String userName) {
		userVO.setUserName(userName);
	}

	public boolean equals(Object obj) {
		return userVO.equals(obj);
	}

	public int hashCode() {
		return userVO.hashCode();
	}

	public String toString() {
		return userVO.toString();
	}
	
	
	

}
